方法一: bot查询
比较方便快捷,这种信息用第三方好像也没什么大问题。
@userinfobot&@groupinfobot
方法二: Api调用
使用https://api.telegram.org/bot<token>/getUpdates该网址能够查看Bot发送和接收的消息,从中获得想要让目标地址的chat id,群组和频道的id前面带横杠。大概如以下形式:
{
"ok": true,
"result": [
{
"update_id": 113527511,
"message": {
"message_id": 2,
"from": {
"id": 8888,
"is_bot": false,
"first_name": "A",
"last_name": "B",
"username": "C",
"language_code": "zh-hans"
},
"chat": {
"id": 8888,
"first_name": "A",
"last_name": "B",
"username": "C",
"type": "private"
},
"date": 1523352556,
"text": "hello"
}
},
{
"update_id": 115523124,
"channel_post": {
"message_id": 4,
"sender_chat": {
"id": -123456,
"title": "Jenkins通知",
"type": "channel"
},
"chat": {
"id": -123456,
"title": "Jenkins通知",
"type": "channel"
},
"date": 152352051,
"text": "channel"
}
},
]
}
里面的8888便是用户id,-123456便是 Jenkins通知 这个频道的id。
获得了id之后,可以直接使用curl来让bot发送消息
curl -s -X POST https://api.telegram.org/bot${TOKEN}/sendMessage -d "chat_id=${CHAT_ID}